﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portal.Workflow.Model;
using System.Data.SqlClient;
using Portal.Core;
using Portal.Web.Utility;
using Portal.Cms.Bussiness;
using Portal.Cms.Utility;
using Portal.Cms.Model;


namespace Portal.Cms.WorkflowFunctions
{
    public class WorkflowFunctionUpdateData : WorkFlowFunctionTemplate
    {
        public override string WfFunctionId
        {
            get
            {
                return "WorkflowFunctionUpdateData";
            }
        }

        public override string Name
        {
            get
            {
                return "Sửa chữa lại";
            }
        }

        public override bool RunAtServer
        {
            get
            {
                return true;
            }
        }

        public override RetWfExecuteParamCls Execute(WfExecuteParamCls oWfExecuteParamCls)
        {
            RetWfExecuteParamCls oRetWfExecuteParamCls = new RetWfExecuteParamCls();
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(oWfExecuteParamCls.SiteId);
            string SiteId=oWfExecuteParamCls.SiteId;
            string WorkflowDefId=oWfExecuteParamCls.WorkflowDefId;
            string WorkflowActionId=oWfExecuteParamCls.WorkflowActionId;
            string RecordId = oWfExecuteParamCls.RecordId;
            CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, oWfExecuteParamCls.RecordId);
            oRetWfExecuteParamCls.ReturnIsLink = true;
            oRetWfExecuteParamCls.Url = OSiteParam.HttpRoot+"/Admin/Modules/Cms/UpdateCmsData.aspx?gid=" + OCmsData.frkGroupDataId + "&CmsDataId=" + OCmsData.DataId+"&back=../../home.aspx";
            return oRetWfExecuteParamCls;
        }

        public override RetNextLinkParam GetLinkUrl(WfExecuteParamCls oWfExecuteParamCls)
        {
            string SiteId = oWfExecuteParamCls.SiteId;
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(oWfExecuteParamCls.SiteId);
            CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, oWfExecuteParamCls.RecordId);
            RetNextLinkParam ORetNextLinkParam = new RetNextLinkParam();
            ORetNextLinkParam.Url = OSiteParam.HttpRoot + "/Admin/Modules/Cms/UpdateCmsData.aspx?gid=" + OCmsData.frkGroupDataId + "&CmsDataId=" + OCmsData.DataId + "&back=../../home.aspx";
            ORetNextLinkParam.Target = "_self";
            return ORetNextLinkParam;
        }
    }
}
